<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>生意帮</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/common.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui-pull-refresh.css" />
    <link rel="stylesheet" type="text/css" href="../../css/swiper.min.css">
    <link rel="stylesheet" type="text/css" href="../../css/aui-slide.css" />
    <style>
        html,
        body {
            background-color: transparent;
        }

        .boxB {
            width: 100%;
            height: 100vh;
            position: relative;
        }

        .mask {
            position: absolute;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.3);
        }

        .aui-bar-nav .aui-btn .aui-iconfont {
            color: #333;
        }

        .box {
            padding: 0 0.5rem;
            background-color: #fff;
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
        }

        .aui-bar-nav .aui-btn {
            padding: 0;
        }

        .aui-bar-nav .aui-title {
            font-size: 0.7rem;
            min-height: 2rem;
        }

        header,
        .aui-bar-nav {
            padding-top: 10px !important;
        }

        .aui-bar-nav {
            border-bottom: 1px solid #e6e6e6;
        }

        .content {
            width: 90%;
            margin: 0 auto;
        }

        .content .aui-col-xs-3 {
            font-size: 0.6rem;
            text-align: center;
            padding: 1rem 0;
        }

        .content .aui-col-xs-3 img {
            width: 2.5rem;
            margin: 0 auto 0.25rem;
        }
    </style>
</head>

<body>
    <div class="boxB">
        <div class="mask" onclick="openF()"></div>
        <div class="box">
            <div class="aui-bar aui-bar-nav">
                <div class="aui-title">分享</div>
                <a class="aui-pull-right aui-btn" onclick="openF()">
                    <span class="aui-iconfont aui-icon-close"></span>
                </a>
            </div>
            <div class="aui-content content">
                <div class="aui-row-padded">
                    <div class="aui-col-xs-3" onclick="share_wx('session')">
                        <img src="../../image/wx.png" alt=""> 微信好友
                    </div>
                    <div class="aui-col-xs-3" onclick="share_wx('timeline')">
                        <img src="../../image/pyq.png" alt=""> 朋友圈
                    </div>
                    <div class="aui-col-xs-3" onclick="share()">
                        <img src="../../image/qq.png" alt=""> QQ
                    </div>
                    <div class="aui-col-xs-3" onclick="share_sj()">
                        <img src="../../image/shejiao.png" alt=""> 社交
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/utils.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/aui-tab.js"></script>
<script type="text/javascript" src="../../script/aui-scroll.js"></script>
<script type="text/javascript" src="../../script/aui-pull-refresh.js"></script>
<script type="text/javascript" src="../../script/swiper.min.js"></script>
<script type="text/javascript" src="../../script/aui-slide.js"></script>
<script type="text/javascript" src="../../script/aui-lazyload.js"></script>
<script type="text/javascript">
    function openF() {
        api.closeFrame();
    }
    apiready = function() {

    }


    // 微信分享
    function share_wx(type) {
        var wx = api.require('wx');
        api.ajax({
            url: window.Url.Freegoods_shareGoods,
            method: 'post',
            data: {
                values: {
                    token: $api.getStorage('token'),
                    goodsId: api.pageParam.goodsid
                }
            }
        }, function(ret, err) {
            if (ret) {
                // console.log("获取要分享的商品信息---"+ JSON.stringify( ret ) );
                if (ret.re == 1) {
                    wx.shareWebpage({
                        apiKey: '',
                        scene: ''+type,
                        title: ''+ret.data.goods_name,
                        description: ''+ret.data.goods_name,
                        thumb: 'widget://image/my/LOGO.png',
                        contentUrl: ''+ret.data.url
                    }, function(ret, err) {
                        if (ret.status) {
                            // alert('分享成功');
                            api.toast({
                                msg: '分享成功',
                                duration: 2000,
                                location: 'bottom'
                            });

                            api.ajax({
                                url: window.Url.Freegoods_goodsShare,
                                method: 'post',
                                data: {
                                    values: {
                                      token: $api.getStorage('token'),
                                      goodsId: api.pageParam.goodsid
                                    }
                                }
                            },function(ret, err){
                                if (ret) {
                                    // alert( JSON.stringify( ret ) );
                                    console.log("调用分享次数接口--"+JSON.stringify(ret))
                                } else {
                                    console.log( JSON.stringify( err ) );
                                }
                            });


                        } else {
                            console.log(err.code);
                        }
                    });
                }
            } else {
                console.log(JSON.stringify(err));
            }
        });

    }


    // 其他分享
    function share(){
      api.toast({
          msg: '功能正在接入中...',
          duration: 2000,
          location: 'middle'
      });

    }


    // 分享到社交
    function share_sj(){
      api.showProgress({
          style: 'default',
          animationType: 'fade',
          title: '努力加载中...',
          text: '先喝杯茶...',
          modal: false
      });

      api.ajax({
        url: window.Url.Community_addDynamic,
        method: 'post',
        data: {
            values: {
                token: $api.getStorage('token'),
                type: 2,
                goods_id: api.pageParam.goodsid
            }
        }
      },function(ret, err){
          // console.log("商品分享到社交板块---"+JSON.stringify(ret));
          if (ret) {
              if(ret.re==1){
                api.hideProgress();

                api.toast({
                    msg: '发布成功，审核中...',
                    duration: 2000,
                    location: 'bottom'
                });

                setTimeout(function(){
                  api.closeFrame({
                      name: 'share'
                  });
                },2000)

              }
          } else {
              alert( JSON.stringify( err ) );
          }
      });

    }
</script>

</html>
